package com.twu.biblioteca.menu;

import com.twu.biblioteca.Index;
import com.twu.biblioteca.Movie;
import com.twu.biblioteca.user.User;

import java.io.IOException;

public class MovieList extends MenuItem {
    private static final String PROMPT = "Enter any key to go back to main menu.";

    protected final String title;
    protected final Index index;
    protected final MenuInputReader reader;

    public MovieList(String title, User user, Index index, MenuInputReader reader)
    {
        super(title, user);
        this.title = title;
        this.index = index;
        this.reader = reader;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(title + "\n");
        for(Movie movie : index.getMovies())
        {
            sb.append(movie.getItemId() + "\t" + movie.getTitle() + "\n");
        }
        sb.append("\n" + PROMPT + "\n");
        return sb.toString();
    }

    @Override
    public void run() {
        try
        {
            reader.readString();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
}
